﻿using BCCommon;
using BCCommon.TMS.FreightEnums;
using BCDto.TMS.HorsemanFreightConfiguration;
using BCService.TMS.HorsemanFreightConfiguration;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Mvc;

namespace BCTMSRESTful.Controllers.Management.TMS.HorsemanFreightConfiguration
{
    /// <summary>
    /// 骑手运费配置
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class HorsemanFreightConfigurationController : ManagementBaseController
    {
        private readonly IHorsemanFreightConfigurationService horsemanFreightConfigurationService;
        public HorsemanFreightConfigurationController(IHorsemanFreightConfigurationService horsemanFreightConfigurationService)
        {
            this.horsemanFreightConfigurationService = horsemanFreightConfigurationService;
        }


        /// <summary>
        /// 创建骑手运费配置
        /// </summary>
        /// <param name="dto">骑手运费配置</param>
        /// <response code="200">创建骑手运费配置成功。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("创建骑手运费配置")]
        [ProducesResponseType(typeof(HorsemanFreightConfigurationDto), 200)]
        public IActionResult Post([FromBody] HorsemanFreightConfigurationRequestDto dto)
        {
            HorsemanFreightConfigurationDto result = this.horsemanFreightConfigurationService.Add(this.Admin, dto);
            return this.Created(string.Format("/api/v1/sim/HorsemanFreightConfiguration/{0}", result.HorsemanFreightConfigurationId), result);
        }

        /// <summary>
        /// 获取指定的骑手运费配置
        /// </summary>
        /// <param name="horsemanFreightConfigurationId">骑手运费配置Id</param>
        /// <response code="200">查询骑手运费配置成功。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <returns></returns>
        [HttpGet("{horseman_freight_configuration_id}")]
        [ProducesResponseType(typeof(HorsemanFreightConfigurationDto), 200)]
        public IActionResult Get([FromRoute(Name = "horseman_freight_configuration_id")] long horsemanFreightConfigurationId)
        {
            return Ok(this.horsemanFreightConfigurationService.GetByHorsemanFreightConfigurationId(horsemanFreightConfigurationId));
        }

        /// <summary>
        /// 更新骑手运费配置信息
        /// </summary>
        /// <param name="horsemanFreightConfigurationId">骑手运费配置Id</param>
        /// <param name="dto">骑手运费配置修改内容</param>
        /// <response code="200">更新骑手运费配置成功。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <returns></returns>
        [HttpPut("{horseman_freight_configuration_id}")]
        [Log("更新骑手运费配置信息")]
        [ProducesResponseType(typeof(HorsemanFreightConfigurationDto), 200)]
        public IActionResult Put([FromRoute(Name = "horseman_freight_configuration_id")] int horsemanFreightConfigurationId, [FromBody] HorsemanFreightConfigurationRequestDto dto)
        {
            return this.Ok(this.horsemanFreightConfigurationService.Update(this.Admin, horsemanFreightConfigurationId, dto));
        }

        /// <summary>
        /// 获取骑手运费配置（分页）
        /// </summary> 
        /// <param name="isBase">是否是基础骑手运费配置</param>     
        /// <param name="countyCode">区县编码</param>
        /// <param name="distanceType">距离计算类型</param>  
        /// <param name="ascending">是否升序排序</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="index">当前页</param>
        /// <param name="size">每页条数</param>
        /// <response code="200">获取骑手运费配置列表成功。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<HorsemanFreightConfigurationViewDto>), 200)]
        public IActionResult Get(
            [FromQuery(Name = "is_base")] bool? isBase,
            [FromQuery(Name = "county_code")] string countyCode,
            [FromQuery(Name = "distance_type")] DistanceCalculateType? distanceType,
            [FromQuery(Name = "ascending")] bool? ascending,
            [FromQuery(Name = "sort_name")] string sortName,
            [FromQuery(Name = "index")] int index = 1,
            [FromQuery(Name = "size")] int size = 10)
        {
            var list = this.horsemanFreightConfigurationService.GetList(this.Admin, isBase, countyCode, distanceType, ascending, sortName, index, size);
            return this.Ok(list);

        }

    }
}
